package cn.zhibang.sannuo.web.controller;

import cn.zhibang.sannuo.commons.model.BranchOffice;
import cn.zhibang.sannuo.commons.model.Cudetails;
import cn.zhibang.sannuo.commons.model.HeadOffice;
import cn.zhibang.sannuo.repoty.service.RcustomerServices;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

@Controller
@RequestMapping("/report")
@Slf4j
public class ReportController {

    @Autowired private RcustomerServices rcustomerServices;
    /**
     *  检测指标统览
     * @return
     */
    @GetMapping("/examiner_test")
    public String examiner_test(Model model){
        List<BranchOffice> branchOffices = rcustomerServices.selBname();
        List<HeadOffice> headOffices = rcustomerServices.selHname();
        model.addAttribute("branchOffices", branchOffices);
        model.addAttribute("headOffices", headOffices);
        return "html/examiner_test";
    }

    /**
     *   指标异常率报表
     * @return
     */
    @GetMapping("/zhibiao_yichang")
    public String zhibiao_yichang(Model model){
        String sex = "";
        LinkedHashMap<String, Object> map = new LinkedHashMap<>();
        for (int i = 0; i<3; i++){
            if(i == 0)sex="0";
            if(i == 1)sex="1";
            if(i == 2)sex="0,1";
            Integer[] count = new Integer[12];
            for (int j = 1; j<=12; j++){
                count[j-1] = rcustomerServices.getMityCount(sex, j);
            }
            map.put("sex"+i, count);
        }
        model.addAttribute("map", map);

        List<HeadOffice> selHname = rcustomerServices.selHname();
        model.addAttribute("selHname", selHname);

        List<Cudetails> cudname = rcustomerServices.queryCudname();
        model.addAttribute("cudname", cudname);

        return "html/zhibiao_yichang";
    }

    /**
     *  消费者数据图谱
     * @return
     */
    @GetMapping("/xiaofeizhe_tupu")
    public String xiaofeizhe_tupu(Model model){

        Integer avgAge = rcustomerServices.getAvgAge();
        Integer mitySum = rcustomerServices.getMitySum();
        Integer sumCount = rcustomerServices.getSumCount();
        Integer abnormal = mitySum/sumCount;
        List<HeadOffice> selHname = rcustomerServices.selHname();

        model.addAttribute("avgAge",avgAge);
        model.addAttribute("mitySum",mitySum);
        model.addAttribute("abnormal",abnormal);
        model.addAttribute("selHname", selHname);
        return "html/xiaofeizhe_tupu";
    }

    /**
     *  月度数据报表
     * @return
     */
    @GetMapping("/yuedu_shuju")
    public String yuedu_shuju(){
        return "html/yuedu_shuju";
    }

    /**
     *  合格率分析
     * @return
     */
    @GetMapping("/hegelv_fenxi")
    public String hegelv_fenxi(Model model){
        List<HeadOffice> selHname = rcustomerServices.selHname();
        model.addAttribute("selHname",selHname);
        return "html/hegelv_fenxi";
    }

    /**
     *  检测记录报表
     * @return
     */
    @GetMapping("/jiancejilu_baobiao")
    public String jiancejilu_baobiao(){
        return "html/jiancejilu_baobiao";
    }

}
